package com.neu.admin;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.neu.common.RequiresPermissionsDesc;
import com.neu.common.validator.Order;
import com.neu.common.validator.Sort;
import com.neu.doc.AdminAdController_list;
import com.neu.doc.AdminUserController_list;
import com.neu.domain.ShoppingUser;
import com.neu.domain.ShoppingUserExample;
import com.neu.service.ShoppingUserService;
import com.neu.util.ResponseUtil;

import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;

import java.util.List;

@RestController
@RequestMapping("/admin/user")
@Validated
public class AdminUserController {
    private final Log logger = LogFactory.getLog(AdminUserController.class);

    @Autowired
    private ShoppingUserService userService;


//    @RequiresPermissions("admin:user:list")
//    @RequiresPermissionsDesc(menu = {"用户管理", "会员管理"}, button = "查询")
//  TODO
    @ApiOperation(value="获取用户信息分页数据", notes="分页查询用户信息",response = AdminUserController_list.class)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "limit", value = "每页多少篇条数据", required = true, dataType = "integer"),
            @ApiImplicitParam(name = "page", value = "当前页数", required = true, dataType = "integer"),
            @ApiImplicitParam(name = "mobile", value = "手机号", required = true, dataType = "string"),
            @ApiImplicitParam(name = "order", value = "排序规则", required = false, dataType = "string"),
            @ApiImplicitParam(name = "sort", value = "排序字段", required = true, dataType = "string"),
            @ApiImplicitParam(name = "username", value = "用户名", required = true, dataType = "string")
    })
    @RequiresPermissions("admin:user:list")
    @RequiresPermissionsDesc(menu = {"用户管理", "会员管理"}, button = "查询")
    @GetMapping("/list")
    public Object list(String username, String mobile,
            @RequestParam(defaultValue = "1") Integer page,
            @RequestParam(defaultValue = "10") Integer limit,
            @Sort @RequestParam(defaultValue = "add_time") String sort,
            @Order @RequestParam(defaultValue = "desc") String order) {
//    	List<ShoppingUser> su = userService.selectByExample(limit, page, mobile, order, sort, username);
//    	return ResponseUtil.ok(su);
    	  List<ShoppingUser> userList = userService.querySelective(username, mobile, page, limit, sort, order);
          return ResponseUtil.okList(userList);
    }
}
